package cn.socket.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * udp 接受口
 */
public class UdpReceive {
    public static void main(String[] args) throws IOException {
        //通过port构造
        DatagramSocket ds=new DatagramSocket(10086);
        //用于接受数据
        byte[] rdata=new byte[1024];
        DatagramPacket data=new DatagramPacket(rdata,rdata.length);
        //接受数据
        ds.receive(data);
        byte[] bytes = data.getData();
        int len=bytes.length;
        String receive = new String(bytes,0,len);
        System.out.println(receive);
        //释放资源
        ds.close();
    }
}
